class Solution:
    def searchInsert(self, nums: List[int], target: int) -> int:
        if nums ==None or len(nums)==0:
            return 0
        left, right = 0, len(nums)-1
        while left < right:
            mid = (left+right) // 2
            if nums[mid] > target:
                right = mid - 1
            elif nums[mid] < target:
                left = mid + 1
            else:
                return mid
        return left if nums[left] >=target else left+1

if __name__ == '__main__':
    s = Solution()
    print(s.searchInsert(nums = [1,3,5,6], target = 5))
    print(s.searchInsert(nums = [1,3,5,6], target = 2))
    print(s.searchInsert(nums = [1,3,5,6], target = 7))
    print(s.searchInsert(nums = [2,3,5,6], target = 1))